package com.yqg.protection.cover;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author zxf
 * @ClassName: DeviceStateConverter
 */
public class DeviceStateConverter implements Converter<String> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if ("正常".equals(cellData.getStringValue())) {
            return "0";
        } else if ("报警".equals(cellData.getStringValue())) {
            return "1";
        } else {
            return "2";
        }
    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value.equals("0")) {
            return new CellData("正常");
        } else if (value.equals("1")) {
            return new CellData("报警");
        } else {
            return new CellData("故障");
        }
    }

}

